{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "things need to do：\n",
    "1) save and output data which its confidence  >= 0.9\n",
    "2) norn_pos_x and norn_pos_y satisfied with normal distribution, select data through 3-sigma rules\n",
    "3) convert the format of \"gaze_timestamp\" as \"year-month-day\"\n",
    "4) the sample rate?\n",
    "5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](./s-sigma.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The number of eligible data rows is: 87442\n"
     ]
    }
   ],
   "source": [
    "#find \"confidence\" >= 0.9, then output the number\n",
    "with open(\"gaze_1.csv\", \"r\") as f1:\n",
    "    reader = csv.reader(f1)\n",
    "    HeadRow = next(reader)\n",
    "    a = 0\n",
    "    for row in reader:\n",
    "        if float(row[2]) >= 0.9:\n",
    "            a += 1\n",
    "print(\"The number of eligible data rows is:\", a)\n",
    "\n",
    "Ord = pd.read_csv(\"gaze_1.csv\")\n",
    "reader1 = Ord.copy(deep=True)\n",
    "NewFile = reader1\n",
    "NewFile = NewFile.loc[reader1[\"confidence\"] >= 0.9]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gaze_timestamp</th>\n",
       "      <th>world_index</th>\n",
       "      <th>confidence</th>\n",
       "      <th>norm_pos_x</th>\n",
       "      <th>norm_pos_y</th>\n",
       "      <th>base_data</th>\n",
       "      <th>gaze_point_3d_x</th>\n",
       "      <th>gaze_point_3d_y</th>\n",
       "      <th>gaze_point_3d_z</th>\n",
       "      <th>eye_center0_3d_x</th>\n",
       "      <th>...</th>\n",
       "      <th>eye_center0_3d_z</th>\n",
       "      <th>gaze_normal0_x</th>\n",
       "      <th>gaze_normal0_y</th>\n",
       "      <th>gaze_normal0_z</th>\n",
       "      <th>eye_center1_3d_x</th>\n",
       "      <th>eye_center1_3d_y</th>\n",
       "      <th>eye_center1_3d_z</th>\n",
       "      <th>gaze_normal1_x</th>\n",
       "      <th>gaze_normal1_y</th>\n",
       "      <th>gaze_normal1_z</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>88150.82564</td>\n",
       "      <td>2</td>\n",
       "      <td>0.915197</td>\n",
       "      <td>0.493612</td>\n",
       "      <td>0.398950</td>\n",
       "      <td>88150.827729-0 88150.823548-1</td>\n",
       "      <td>2.412810</td>\n",
       "      <td>-21.468145</td>\n",
       "      <td>-295.071057</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.062883</td>\n",
       "      <td>0.025100</td>\n",
       "      <td>0.997705</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.150041</td>\n",
       "      <td>0.234536</td>\n",
       "      <td>0.960458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>88150.82773</td>\n",
       "      <td>2</td>\n",
       "      <td>0.915197</td>\n",
       "      <td>0.493561</td>\n",
       "      <td>0.399305</td>\n",
       "      <td>88150.827729-0 88150.827729-1</td>\n",
       "      <td>2.429837</td>\n",
       "      <td>-21.374413</td>\n",
       "      <td>-294.819200</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.062883</td>\n",
       "      <td>0.025100</td>\n",
       "      <td>0.997705</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.150243</td>\n",
       "      <td>0.234115</td>\n",
       "      <td>0.960530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>88150.82966</td>\n",
       "      <td>2</td>\n",
       "      <td>0.915197</td>\n",
       "      <td>0.493570</td>\n",
       "      <td>0.399542</td>\n",
       "      <td>88150.827729-0 88150.83159799999-1</td>\n",
       "      <td>2.427118</td>\n",
       "      <td>-21.328193</td>\n",
       "      <td>-294.874516</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.062883</td>\n",
       "      <td>0.025100</td>\n",
       "      <td>0.997705</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.150210</td>\n",
       "      <td>0.233747</td>\n",
       "      <td>0.960624</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>88150.86601</td>\n",
       "      <td>3</td>\n",
       "      <td>0.922197</td>\n",
       "      <td>0.492592</td>\n",
       "      <td>0.398705</td>\n",
       "      <td>88150.867514-0 88150.86451599999-1</td>\n",
       "      <td>2.827911</td>\n",
       "      <td>-21.750938</td>\n",
       "      <td>-298.233246</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.060717</td>\n",
       "      <td>0.025220</td>\n",
       "      <td>0.997836</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149814</td>\n",
       "      <td>0.233510</td>\n",
       "      <td>0.960744</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>88150.86962</td>\n",
       "      <td>3</td>\n",
       "      <td>0.922197</td>\n",
       "      <td>0.492635</td>\n",
       "      <td>0.398814</td>\n",
       "      <td>88150.867514-0 88150.871726-1</td>\n",
       "      <td>2.813774</td>\n",
       "      <td>-21.744854</td>\n",
       "      <td>-298.471253</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.060717</td>\n",
       "      <td>0.025220</td>\n",
       "      <td>0.997836</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149645</td>\n",
       "      <td>0.233258</td>\n",
       "      <td>0.960831</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>88150.87752</td>\n",
       "      <td>4</td>\n",
       "      <td>0.945000</td>\n",
       "      <td>0.492094</td>\n",
       "      <td>0.398930</td>\n",
       "      <td>88150.879586-0 88150.87545699999-1</td>\n",
       "      <td>3.018227</td>\n",
       "      <td>-21.704820</td>\n",
       "      <td>-298.264650</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.060040</td>\n",
       "      <td>0.024936</td>\n",
       "      <td>0.997884</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.150451</td>\n",
       "      <td>0.233436</td>\n",
       "      <td>0.960662</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>88150.87958</td>\n",
       "      <td>4</td>\n",
       "      <td>0.945000</td>\n",
       "      <td>0.492159</td>\n",
       "      <td>0.398855</td>\n",
       "      <td>88150.879586-0 88150.87958299999-1</td>\n",
       "      <td>2.996872</td>\n",
       "      <td>-21.746449</td>\n",
       "      <td>-298.615702</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.060040</td>\n",
       "      <td>0.024936</td>\n",
       "      <td>0.997884</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.150193</td>\n",
       "      <td>0.233409</td>\n",
       "      <td>0.960709</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>88150.88174</td>\n",
       "      <td>4</td>\n",
       "      <td>0.945000</td>\n",
       "      <td>0.492318</td>\n",
       "      <td>0.398976</td>\n",
       "      <td>88150.879586-0 88150.88389-1</td>\n",
       "      <td>2.944876</td>\n",
       "      <td>-21.783872</td>\n",
       "      <td>-299.486159</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.060040</td>\n",
       "      <td>0.024936</td>\n",
       "      <td>0.997884</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149568</td>\n",
       "      <td>0.232896</td>\n",
       "      <td>0.960931</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>88150.88389</td>\n",
       "      <td>4</td>\n",
       "      <td>0.933658</td>\n",
       "      <td>0.492335</td>\n",
       "      <td>0.399325</td>\n",
       "      <td>88150.88389-0 88150.88389-1</td>\n",
       "      <td>2.937930</td>\n",
       "      <td>-21.705329</td>\n",
       "      <td>-299.442625</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.060074</td>\n",
       "      <td>0.024427</td>\n",
       "      <td>0.997895</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149568</td>\n",
       "      <td>0.232896</td>\n",
       "      <td>0.960931</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>88150.88608</td>\n",
       "      <td>4</td>\n",
       "      <td>0.933658</td>\n",
       "      <td>0.492166</td>\n",
       "      <td>0.399167</td>\n",
       "      <td>88150.88389-0 88150.88827099999-1</td>\n",
       "      <td>2.993380</td>\n",
       "      <td>-21.671916</td>\n",
       "      <td>-298.513329</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.060074</td>\n",
       "      <td>0.024427</td>\n",
       "      <td>0.997895</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.150235</td>\n",
       "      <td>0.233487</td>\n",
       "      <td>0.960684</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>88150.89170</td>\n",
       "      <td>4</td>\n",
       "      <td>0.923014</td>\n",
       "      <td>0.491745</td>\n",
       "      <td>0.397902</td>\n",
       "      <td>88150.891699-0 88150.891702-1</td>\n",
       "      <td>3.194857</td>\n",
       "      <td>-22.225656</td>\n",
       "      <td>-302.346860</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.058560</td>\n",
       "      <td>0.024551</td>\n",
       "      <td>0.997982</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.148916</td>\n",
       "      <td>0.233733</td>\n",
       "      <td>0.960829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>88150.91139</td>\n",
       "      <td>5</td>\n",
       "      <td>0.929133</td>\n",
       "      <td>0.491363</td>\n",
       "      <td>0.398149</td>\n",
       "      <td>88150.91139099999-0 88150.91137999999-1</td>\n",
       "      <td>3.339173</td>\n",
       "      <td>-22.149845</td>\n",
       "      <td>-302.044727</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.058121</td>\n",
       "      <td>0.024277</td>\n",
       "      <td>0.998014</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149559</td>\n",
       "      <td>0.233748</td>\n",
       "      <td>0.960726</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>88150.91420</td>\n",
       "      <td>5</td>\n",
       "      <td>0.929133</td>\n",
       "      <td>0.491439</td>\n",
       "      <td>0.397481</td>\n",
       "      <td>88150.91139099999-0 88150.91700799999-1</td>\n",
       "      <td>3.314201</td>\n",
       "      <td>-22.323971</td>\n",
       "      <td>-302.438158</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.058121</td>\n",
       "      <td>0.024277</td>\n",
       "      <td>0.998014</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149256</td>\n",
       "      <td>0.234575</td>\n",
       "      <td>0.960571</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>88150.93188</td>\n",
       "      <td>5</td>\n",
       "      <td>0.998202</td>\n",
       "      <td>0.491173</td>\n",
       "      <td>0.396201</td>\n",
       "      <td>88150.93622799999-0 88150.92752699999-1</td>\n",
       "      <td>3.440890</td>\n",
       "      <td>-22.760252</td>\n",
       "      <td>-304.543969</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.057256</td>\n",
       "      <td>0.025568</td>\n",
       "      <td>0.998032</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.148602</td>\n",
       "      <td>0.234394</td>\n",
       "      <td>0.960717</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>88150.93392</td>\n",
       "      <td>5</td>\n",
       "      <td>0.998348</td>\n",
       "      <td>0.490991</td>\n",
       "      <td>0.396183</td>\n",
       "      <td>88150.93622799999-0 88150.931606-1</td>\n",
       "      <td>3.499815</td>\n",
       "      <td>-22.687283</td>\n",
       "      <td>-303.516205</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.057256</td>\n",
       "      <td>0.025568</td>\n",
       "      <td>0.998032</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149319</td>\n",
       "      <td>0.234804</td>\n",
       "      <td>0.960505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>88150.93618</td>\n",
       "      <td>5</td>\n",
       "      <td>0.997672</td>\n",
       "      <td>0.491097</td>\n",
       "      <td>0.396252</td>\n",
       "      <td>88150.93622799999-0 88150.936133-1</td>\n",
       "      <td>3.465530</td>\n",
       "      <td>-22.717124</td>\n",
       "      <td>-304.117339</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.057256</td>\n",
       "      <td>0.025568</td>\n",
       "      <td>0.998032</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.148901</td>\n",
       "      <td>0.234478</td>\n",
       "      <td>0.960650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>88150.93856</td>\n",
       "      <td>5</td>\n",
       "      <td>0.998744</td>\n",
       "      <td>0.491162</td>\n",
       "      <td>0.396321</td>\n",
       "      <td>88150.93622799999-0 88150.94089099999-1</td>\n",
       "      <td>3.444671</td>\n",
       "      <td>-22.729378</td>\n",
       "      <td>-304.484514</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.057256</td>\n",
       "      <td>0.025568</td>\n",
       "      <td>0.998032</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.148648</td>\n",
       "      <td>0.234240</td>\n",
       "      <td>0.960747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>88150.94368</td>\n",
       "      <td>6</td>\n",
       "      <td>0.914784</td>\n",
       "      <td>0.491071</td>\n",
       "      <td>0.396681</td>\n",
       "      <td>88150.94368499999-0 88150.94368499999-1</td>\n",
       "      <td>3.468186</td>\n",
       "      <td>-22.574627</td>\n",
       "      <td>-303.463997</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.057382</td>\n",
       "      <td>0.025709</td>\n",
       "      <td>0.998021</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149255</td>\n",
       "      <td>0.233960</td>\n",
       "      <td>0.960721</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>88150.94560</td>\n",
       "      <td>6</td>\n",
       "      <td>0.914784</td>\n",
       "      <td>0.491358</td>\n",
       "      <td>0.396020</td>\n",
       "      <td>88150.94368499999-0 88150.947523-1</td>\n",
       "      <td>3.374399</td>\n",
       "      <td>-22.838474</td>\n",
       "      <td>-305.059578</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.057382</td>\n",
       "      <td>0.025709</td>\n",
       "      <td>0.998021</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.148117</td>\n",
       "      <td>0.234331</td>\n",
       "      <td>0.960807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>88151.01362</td>\n",
       "      <td>8</td>\n",
       "      <td>0.912810</td>\n",
       "      <td>0.490732</td>\n",
       "      <td>0.396126</td>\n",
       "      <td>88151.01567699999-0 88151.011554-1</td>\n",
       "      <td>3.611114</td>\n",
       "      <td>-22.764706</td>\n",
       "      <td>-304.385381</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>0.056702</td>\n",
       "      <td>0.025972</td>\n",
       "      <td>0.998053</td>\n",
       "      <td>-39.934928</td>\n",
       "      <td>14.997919</td>\n",
       "      <td>-20.075283</td>\n",
       "      <td>-0.149256</td>\n",
       "      <td>0.234162</td>\n",
       "      <td>0.960672</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     gaze_timestamp  world_index  confidence  norm_pos_x  norm_pos_y  \\\n",
       "21      88150.82564            2    0.915197    0.493612    0.398950   \n",
       "22      88150.82773            2    0.915197    0.493561    0.399305   \n",
       "23      88150.82966            2    0.915197    0.493570    0.399542   \n",
       "39      88150.86601            3    0.922197    0.492592    0.398705   \n",
       "40      88150.86962            3    0.922197    0.492635    0.398814   \n",
       "43      88150.87752            4    0.945000    0.492094    0.398930   \n",
       "44      88150.87958            4    0.945000    0.492159    0.398855   \n",
       "45      88150.88174            4    0.945000    0.492318    0.398976   \n",
       "46      88150.88389            4    0.933658    0.492335    0.399325   \n",
       "47      88150.88608            4    0.933658    0.492166    0.399167   \n",
       "50      88150.89170            4    0.923014    0.491745    0.397902   \n",
       "58      88150.91139            5    0.929133    0.491363    0.398149   \n",
       "59      88150.91420            5    0.929133    0.491439    0.397481   \n",
       "66      88150.93188            5    0.998202    0.491173    0.396201   \n",
       "67      88150.93392            5    0.998348    0.490991    0.396183   \n",
       "68      88150.93618            5    0.997672    0.491097    0.396252   \n",
       "69      88150.93856            5    0.998744    0.491162    0.396321   \n",
       "72      88150.94368            6    0.914784    0.491071    0.396681   \n",
       "73      88150.94560            6    0.914784    0.491358    0.396020   \n",
       "101     88151.01362            8    0.912810    0.490732    0.396126   \n",
       "\n",
       "                                   base_data  gaze_point_3d_x  \\\n",
       "21             88150.827729-0 88150.823548-1         2.412810   \n",
       "22             88150.827729-0 88150.827729-1         2.429837   \n",
       "23        88150.827729-0 88150.83159799999-1         2.427118   \n",
       "39        88150.867514-0 88150.86451599999-1         2.827911   \n",
       "40             88150.867514-0 88150.871726-1         2.813774   \n",
       "43        88150.879586-0 88150.87545699999-1         3.018227   \n",
       "44        88150.879586-0 88150.87958299999-1         2.996872   \n",
       "45              88150.879586-0 88150.88389-1         2.944876   \n",
       "46               88150.88389-0 88150.88389-1         2.937930   \n",
       "47         88150.88389-0 88150.88827099999-1         2.993380   \n",
       "50             88150.891699-0 88150.891702-1         3.194857   \n",
       "58   88150.91139099999-0 88150.91137999999-1         3.339173   \n",
       "59   88150.91139099999-0 88150.91700799999-1         3.314201   \n",
       "66   88150.93622799999-0 88150.92752699999-1         3.440890   \n",
       "67        88150.93622799999-0 88150.931606-1         3.499815   \n",
       "68        88150.93622799999-0 88150.936133-1         3.465530   \n",
       "69   88150.93622799999-0 88150.94089099999-1         3.444671   \n",
       "72   88150.94368499999-0 88150.94368499999-1         3.468186   \n",
       "73        88150.94368499999-0 88150.947523-1         3.374399   \n",
       "101       88151.01567699999-0 88151.011554-1         3.611114   \n",
       "\n",
       "     gaze_point_3d_y  gaze_point_3d_z  eye_center0_3d_x  ...  \\\n",
       "21        -21.468145      -295.071057              20.0  ...   \n",
       "22        -21.374413      -294.819200              20.0  ...   \n",
       "23        -21.328193      -294.874516              20.0  ...   \n",
       "39        -21.750938      -298.233246              20.0  ...   \n",
       "40        -21.744854      -298.471253              20.0  ...   \n",
       "43        -21.704820      -298.264650              20.0  ...   \n",
       "44        -21.746449      -298.615702              20.0  ...   \n",
       "45        -21.783872      -299.486159              20.0  ...   \n",
       "46        -21.705329      -299.442625              20.0  ...   \n",
       "47        -21.671916      -298.513329              20.0  ...   \n",
       "50        -22.225656      -302.346860              20.0  ...   \n",
       "58        -22.149845      -302.044727              20.0  ...   \n",
       "59        -22.323971      -302.438158              20.0  ...   \n",
       "66        -22.760252      -304.543969              20.0  ...   \n",
       "67        -22.687283      -303.516205              20.0  ...   \n",
       "68        -22.717124      -304.117339              20.0  ...   \n",
       "69        -22.729378      -304.484514              20.0  ...   \n",
       "72        -22.574627      -303.463997              20.0  ...   \n",
       "73        -22.838474      -305.059578              20.0  ...   \n",
       "101       -22.764706      -304.385381              20.0  ...   \n",
       "\n",
       "     eye_center0_3d_z  gaze_normal0_x  gaze_normal0_y  gaze_normal0_z  \\\n",
       "21              -20.0        0.062883        0.025100        0.997705   \n",
       "22              -20.0        0.062883        0.025100        0.997705   \n",
       "23              -20.0        0.062883        0.025100        0.997705   \n",
       "39              -20.0        0.060717        0.025220        0.997836   \n",
       "40              -20.0        0.060717        0.025220        0.997836   \n",
       "43              -20.0        0.060040        0.024936        0.997884   \n",
       "44              -20.0        0.060040        0.024936        0.997884   \n",
       "45              -20.0        0.060040        0.024936        0.997884   \n",
       "46              -20.0        0.060074        0.024427        0.997895   \n",
       "47              -20.0        0.060074        0.024427        0.997895   \n",
       "50              -20.0        0.058560        0.024551        0.997982   \n",
       "58              -20.0        0.058121        0.024277        0.998014   \n",
       "59              -20.0        0.058121        0.024277        0.998014   \n",
       "66              -20.0        0.057256        0.025568        0.998032   \n",
       "67              -20.0        0.057256        0.025568        0.998032   \n",
       "68              -20.0        0.057256        0.025568        0.998032   \n",
       "69              -20.0        0.057256        0.025568        0.998032   \n",
       "72              -20.0        0.057382        0.025709        0.998021   \n",
       "73              -20.0        0.057382        0.025709        0.998021   \n",
       "101             -20.0        0.056702        0.025972        0.998053   \n",
       "\n",
       "     eye_center1_3d_x  eye_center1_3d_y  eye_center1_3d_z  gaze_normal1_x  \\\n",
       "21         -39.934928         14.997919        -20.075283       -0.150041   \n",
       "22         -39.934928         14.997919        -20.075283       -0.150243   \n",
       "23         -39.934928         14.997919        -20.075283       -0.150210   \n",
       "39         -39.934928         14.997919        -20.075283       -0.149814   \n",
       "40         -39.934928         14.997919        -20.075283       -0.149645   \n",
       "43         -39.934928         14.997919        -20.075283       -0.150451   \n",
       "44         -39.934928         14.997919        -20.075283       -0.150193   \n",
       "45         -39.934928         14.997919        -20.075283       -0.149568   \n",
       "46         -39.934928         14.997919        -20.075283       -0.149568   \n",
       "47         -39.934928         14.997919        -20.075283       -0.150235   \n",
       "50         -39.934928         14.997919        -20.075283       -0.148916   \n",
       "58         -39.934928         14.997919        -20.075283       -0.149559   \n",
       "59         -39.934928         14.997919        -20.075283       -0.149256   \n",
       "66         -39.934928         14.997919        -20.075283       -0.148602   \n",
       "67         -39.934928         14.997919        -20.075283       -0.149319   \n",
       "68         -39.934928         14.997919        -20.075283       -0.148901   \n",
       "69         -39.934928         14.997919        -20.075283       -0.148648   \n",
       "72         -39.934928         14.997919        -20.075283       -0.149255   \n",
       "73         -39.934928         14.997919        -20.075283       -0.148117   \n",
       "101        -39.934928         14.997919        -20.075283       -0.149256   \n",
       "\n",
       "     gaze_normal1_y  gaze_normal1_z  \n",
       "21         0.234536        0.960458  \n",
       "22         0.234115        0.960530  \n",
       "23         0.233747        0.960624  \n",
       "39         0.233510        0.960744  \n",
       "40         0.233258        0.960831  \n",
       "43         0.233436        0.960662  \n",
       "44         0.233409        0.960709  \n",
       "45         0.232896        0.960931  \n",
       "46         0.232896        0.960931  \n",
       "47         0.233487        0.960684  \n",
       "50         0.233733        0.960829  \n",
       "58         0.233748        0.960726  \n",
       "59         0.234575        0.960571  \n",
       "66         0.234394        0.960717  \n",
       "67         0.234804        0.960505  \n",
       "68         0.234478        0.960650  \n",
       "69         0.234240        0.960747  \n",
       "72         0.233960        0.960721  \n",
       "73         0.234331        0.960807  \n",
       "101        0.234162        0.960672  \n",
       "\n",
       "[20 rows x 21 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Use 3-sigma rules to select\n",
    "MeanX = np.mean(NewFile[\"norm_pos_x\"])\n",
    "SigmaX = np.std(NewFile[\"norm_pos_x\"])\n",
    "\n",
    "MeanY = np.mean(NewFile[\"norm_pos_y\"])\n",
    "SigmaY = np.std(NewFile[\"norm_pos_y\"])\n",
    "\n",
    "SatisfiedFile = NewFile.loc[\n",
    "    (NewFile[\"norm_pos_x\"] >= MeanX - 3*SigmaX)\n",
    "    & (NewFile[\"norm_pos_x\"] <= MeanX + 3*SigmaX)\n",
    "    & (NewFile[\"norm_pos_y\"] >= MeanY - 3*SigmaY)\n",
    "    & (NewFile[\"norm_pos_y\"] <= MeanY + 3*SigmaY)\n",
    "]\n",
    "\n",
    "#%用and会报错\n",
    "SatisfiedFile[0:20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1970-01-02T 00:29:10.776780+0000',\n",
       " '1970-01-02T 00:29:10.776790+0000',\n",
       " '1970-01-02T 00:29:10.779710+0000',\n",
       " '1970-01-02T 00:29:10.779760+0000',\n",
       " '1970-01-02T 00:29:10.787490+0000',\n",
       " '1970-01-02T 00:29:10.787580+0000',\n",
       " '1970-01-02T 00:29:10.789480+0000',\n",
       " '1970-01-02T 00:29:10.793580+0000',\n",
       " '1970-01-02T 00:29:10.795680+0000',\n",
       " '1970-01-02T 00:29:10.798410+0000',\n",
       " '1970-01-02T 00:29:10.801140+0000',\n",
       " '1970-01-02T 00:29:10.802970+0000',\n",
       " '1970-01-02T 00:29:10.804630+0000',\n",
       " '1970-01-02T 00:29:10.807270+0000',\n",
       " '1970-01-02T 00:29:10.809750+0000',\n",
       " '1970-01-02T 00:29:10.812870+0000',\n",
       " '1970-01-02T 00:29:10.814140+0000',\n",
       " '1970-01-02T 00:29:10.816000+0000',\n",
       " '1970-01-02T 00:29:10.818050+0000',\n",
       " '1970-01-02T 00:29:10.821820+0000']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#modify timestamp('gaze_timestamp') to date format(y-m-d-h-m-s)\n",
    "\n",
    "timestamp = Ord[\"gaze_timestamp\"]\n",
    "tl = []\n",
    "for y in timestamp:\n",
    "    trans = datetime.datetime.fromtimestamp(y,datetime.timezone.utc).strftime(\"%Y-%m-%dT %H:%M:%S.%f%z\")\n",
    "    tl.append(trans)\n",
    "    \n",
    "tl[0:20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "427.69745267282633"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Calculate the sample rate of the sample(by the timestamp)\n",
    "StartTime = float(SatisfiedFile[\"gaze_timestamp\"].iloc[0])\n",
    "EndtTime = float(SatisfiedFile[\"gaze_timestamp\"].iloc[-1])\n",
    "\n",
    "SampleRate = len(Ord)/(EndtTime-StartTime)\n",
    "SampleRate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['88150.77', '0', '0.828005946', '0.531432713', '0.397509462', '88150.77678-0', '28.3697529', '52.03313456', '705.1211159', '20', '15', '-20', '0.011526769', '0.05100179', '0.99863204', '', '', '', '', '', '']\n",
      "['88150.78', '1', '0.50259488', '0.340108912', '0.142989495', '88150.787485-1', '-139.4048601', '175.0883214', '681.1514528', '-39.93492801', '14.99791945', '-20.07528253', '-0.136989337', '0.22047545', '0.965724856', '', '', '', '', '', '']\n",
      "['88150.79', '1', '0.625134035', '0.495992731', '0.399020684', '88150.79569-0 88150.79147699999-1', '1.533099949', '-21.7308616', '-298.8904405', '20', '15', '-20', '0.06514516', '0.027374146', '0.997500258', '-39.93492801', '14.99791945', '-20.07528253', '-0.145087255', '0.230744394', '0.962136536']\n",
      "['88150.80', '1', '0.708476074', '0.495145416', '0.408338473', '88150.801157-0 88150.801123-1', '1.782443785', '-18.93099285', '-286.8493091', '20', '15', '-20', '0.067222081', '0.026625008', '0.997382725', '-39.93492801', '14.99791945', '-20.07528253', '-0.152522642', '0.222659333', '0.962891305']\n",
      "['88150.81', '2', '0.856340761', '0.49480892', '0.402125481', '88150.809749-0 88150.815997-1', '1.914320557', '-20.30247952', '-288.1024451', '20', '15', '-20', '0.066337739', '0.023839908', '0.997512387', '-39.93492801', '14.99791945', '-20.07528253', '-0.152093872', '0.233980362', '0.960271131']\n",
      "['88150.82', '2', '0.861112802', '0.493452992', '0.399838536', '88150.823534-0 88150.820104-1', '2.451823208', '-21.09937029', '-292.5744058', '20', '15', '-20', '0.063319819', '0.025199444', '0.997675092', '-39.93492801', '14.99791945', '-20.07528253', '-0.151527396', '0.234143013', '0.960321039']\n",
      "['88150.83', '2', '0.792455434', '0.493562742', '0.398006681', '88150.831679-0 88150.83159799999-1', '2.429747589', '-21.6548145', '-294.8833474', '20', '15', '-20', '0.062870061', '0.027410668', '0.997645233', '-39.93492801', '14.99791945', '-20.07528253', '-0.150210472', '0.233746547', '0.960624467']\n",
      "['88150.84', '2', '0.861800715', '0.492773876', '0.39944442', '88150.841019-0 88150.84344899999-1', '2.740186326', '-21.4488181', '-296.2543203', '20', '15', '-20', '0.061462252', '0.024974843', '0.997796898', '-39.93492801', '14.99791945', '-20.07528253', '-0.150562124', '0.233448037', '0.960642004']\n",
      "['88150.85', '3', '0.814634635', '0.492873494', '0.398929824', '88150.85153599999-0 88150.851534-1', '2.713785009', '-21.64932512', '-297.5012828', '20', '15', '-20', '0.061283019', '0.025668513', '0.997790318', '-39.93492801', '14.99791945', '-20.07528253', '-0.149816675', '0.233035966', '0.960858576']\n",
      "['88150.86', '3', '0.865288341', '0.492818966', '0.39798609', '88150.864506-0 88150.85956499999-1', '2.747911798', '-21.95824899', '-298.9549967', '20', '15', '-20', '0.060837375', '0.025457537', '0.997822994', '-39.93492801', '14.99791945', '-20.07528253', '-0.149151859', '0.234053214', '0.960714742']\n",
      "['88150.87', '3', '0.779777956', '0.49225284', '0.398469793', '88150.87172699999-0 88150.871726-1', '2.969823973', '-21.89303602', '-299.48717', '20', '15', '-20', '0.05994958', '0.025324603', '0.997880109', '-39.93492801', '14.99791945', '-20.07528253', '-0.149645418', '0.233257839', '0.960831426']\n",
      "['88150.88', '4', '0.945000471', '0.492317895', '0.398975706', '88150.879586-0 88150.88389-1', '2.944875662', '-21.78387202', '-299.486159', '20', '15', '-20', '0.060040362', '0.024936294', '0.99788443', '-39.93492801', '14.99791945', '-20.07528253', '-0.149568256', '0.232895646', '0.960931296']\n",
      "['88150.89', '4', '0.825606805', '0.492182499', '0.397400267', '88150.888291-0 88150.891702-1', '3.013482745', '-22.24690193', '-301.1555089', '20', '15', '-20', '0.05943898', '0.025782407', '0.99789893', '-39.93492801', '14.99791945', '-20.07528253', '-0.148915824', '0.233733232', '0.960829253']\n",
      "['88150.90', '4', '0.821102522', '0.491613459', '0.397494745', '88150.89951199999-0 88150.90357499999-1', '3.240232461', '-22.27727032', '-301.8445575', '20', '15', '-20', '0.058503551', '0.025052783', '0.997972792', '-39.93492801', '14.99791945', '-20.07528253', '-0.149322254', '0.23403122', '0.960693631']\n",
      "['88150.91', '5', '0.929132762', '0.491363104', '0.398148615', '88150.91139099999-0 88150.91137999999-1', '3.339172826', '-22.14984503', '-302.0447272', '20', '15', '-20', '0.058120769', '0.024277222', '0.998014325', '-39.93492801', '14.99791945', '-20.07528253', '-0.149559391', '0.233747564', '0.960725801']\n",
      "['88150.92', '5', '0.856588177', '0.491535186', '0.396165551', '88150.91942399999-0 88150.92752699999-1', '3.288905094', '-22.69331226', '-303.5455907', '20', '15', '-20', '0.057982053', '0.026013439', '0.997978648', '-39.93492801', '14.99791945', '-20.07528253', '-0.148601659', '0.234394242', '0.960716861']\n",
      "['88150.93', '5', '0.998202317', '0.491173047', '0.396200664', '88150.93622799999-0 88150.92752699999-1', '3.440890035', '-22.76025241', '-304.5439691', '20', '15', '-20', '0.057255736', '0.025567573', '0.998032104', '-39.93492801', '14.99791945', '-20.07528253', '-0.148601659', '0.234394242', '0.960716861']\n",
      "['88150.94', '5', '0.739420778', '0.49142312', '0.397075337', '88150.940894-0 88150.94089099999-1', '3.33488529', '-22.51093612', '-303.7677084', '20', '15', '-20', '0.057780027', '0.024714738', '0.998023372', '-39.93492801', '14.99791945', '-20.07528253', '-0.148647506', '0.23424002', '0.960747382']\n",
      "['88150.95', '6', '0.803616379', '0.491446201', '0.396408371', '88150.947523-0 88150.95548399999-1', '3.321166939', '-22.62449331', '-303.3344266', '20', '15', '-20', '0.057914416', '0.025849307', '0.99798684', '-39.93492801', '14.99791945', '-20.07528253', '-0.148820867', '0.234277045', '0.960711515']\n",
      "['88150.96', '6', '0.839118919', '0.490797009', '0.397549338', '88150.963521-0 88150.95945699999-1', '3.571551466', '-22.36481116', '-303.1921606', '20', '15', '-20', '0.057074997', '0.023794625', '0.998086299', '-39.93492801', '14.99791945', '-20.07528253', '-0.149732915', '0.234648548', '0.960479106']\n"
     ]
    }
   ],
   "source": [
    "#Process the timestamp at 100hz\n",
    "with open('gaze_1.csv','r') as csvfile:\n",
    "    reader=csv.reader(csvfile)\n",
    "    list1=[]\n",
    "    for i in reader:\n",
    "        list1.append(i)\n",
    "    list1.pop(0)\n",
    "    p=0  \n",
    "    for i in list1:\n",
    "        i[0]=i[0][:8]\n",
    "    a=float(list1[0][0])\n",
    "    while p<20:\n",
    "        if len(list1)==0:           \n",
    "            break\n",
    "        if a == float(list1[0][0]):\n",
    "            print(list1[0])\n",
    "            list1.pop(0)\n",
    "            a = round(a+0.01, 2)\n",
    "            p+=1\n",
    "        else:\n",
    "            list1.pop(0)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
